﻿// <copyright file="Env.cs" company="Lu Studio">
// Copyright (c) Lu Studio. All rights reserved.
// </copyright>
// <author>lu qi</author>
// <createTime>2021-06-19</createTime>

namespace ElfKit.Common
{
    using System.Globalization;
    using System.Threading;

    /// <summary>
    /// 环境.
    /// </summary>
    public static class Env
    {
        #region 定义

        /// <summary>
        /// 默认<see cref="CultureInfo"/>实例.
        /// </summary>
        private static CultureInfo innerDefaultCulture;

        #endregion

        /// <summary>
        /// 设置默认的<see cref="CultureInfo"/>.
        /// </summary>
        /// <param name="culture">文化名称.</param>
        public static void SetDefaultCulture(string culture)
        {
            innerDefaultCulture = new CultureInfo(culture);
        }

        /// <summary>
        /// 获得默认的<see cref="CultureInfo"/>.
        /// </summary>
        /// <returns>默认的<see cref="CultureInfo"/>.</returns>
        public static CultureInfo GetDefaultCulture()
        {
            return innerDefaultCulture ??= new CultureInfo(Constant.CultureNames.ZhCn);
        }

        /// <summary>
        /// 设置当前的<see cref="CultureInfo"/>.
        /// </summary>
        /// <param name="culture">文化名称.</param>
        public static void SetCurrentCulture(string culture)
        {
            CultureInfo ci = new CultureInfo(culture);
            Thread.CurrentThread.CurrentCulture = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
        }

        /// <summary>
        /// 获得当前的<see cref="CultureInfo"/>.
        /// </summary>
        /// <returns>当前的<see cref="CultureInfo"/>.</returns>
        public static CultureInfo GetCurrentCulture()
        {
            return Thread.CurrentThread.CurrentCulture;
        }
    }
}